
/* SDED: start date & expire date */

#ifndef USER_PASSWORD_DYNAMIC_SDED_H
#define USER_PASSWORD_DYNAMIC_SDED_H

#ifndef USER_PASSWORD_DYNAMIC_H
#error "include user_password_dynamic.h instead!"
#endif

#ifdef GKT_CONFIG_USER_PASSWORD_DYNAMIC_SDED_ENABLE
#define USER_DYNPWD_SDED_ENABLE	\
	GKT_CONFIG_USER_PASSWORD_DYNAMIC_SDED_ENABLE
#else
#define USER_DYNPWD_SDED_ENABLE	0
#endif

#define USER_DYNPWD_SDED_DIGITS_SIZE	13

#define USER_DYNPWD_SDED_SD_YEAR_OFFSET_MAX	15
#define USER_DYNPWD_SDED_ED_YEAR_OFFSET_MAX	5
#define USER_DYNPWD_SDED_TAG_VALUE	0x0A	/* 0b1010 */

#define USER_DYNPWD_SDED_SD_DAY_BITS	5
#define USER_DYNPWD_SDED_SD_MONTH_BITS	4
#define USER_DYNPWD_SDED_SD_YEAR_OFFSET_BITS	4
#define USER_DYNPWD_SDED_ED_DAY_BITS	5
#define USER_DYNPWD_SDED_ED_MONTH_BITS	4
#define USER_DYNPWD_SDED_ED_YEAR_OFFSET_BITS	3
#define USER_DYNPWD_SDED_TAG_BITS	4

#define USER_DYNPWD_SDED_FIELD_MASK(FIELD)	\
	((1U << USER_DYNPWD_SDED_##FIELD##_BITS) - 1)

#define USER_DYNPWD_SDED_SD_DAY_SHIFT	\
	(USER_DYNPWD_GENERAL_SHIFT + USER_DYNPWD_GENERAL_BITS)
#define USER_DYNPWD_SDED_SD_MONTH_SHIFT	\
	(USER_DYNPWD_SDED_SD_DAY_SHIFT + USER_DYNPWD_SDED_SD_DAY_BITS)
#define USER_DYNPWD_SDED_SD_YEAR_OFFSET_SHIFT	\
	(USER_DYNPWD_SDED_SD_MONTH_SHIFT + USER_DYNPWD_SDED_SD_MONTH_BITS)
#define USER_DYNPWD_SDED_ED_DAY_SHIFT	\
	(USER_DYNPWD_SDED_SD_YEAR_OFFSET_SHIFT + USER_DYNPWD_SDED_SD_YEAR_OFFSET_BITS)
#define USER_DYNPWD_SDED_ED_MONTH_SHIFT	\
	(USER_DYNPWD_SDED_ED_DAY_SHIFT + USER_DYNPWD_SDED_ED_DAY_BITS)
#define USER_DYNPWD_SDED_ED_YEAR_OFFSET_SHIFT	\
	(USER_DYNPWD_SDED_ED_MONTH_SHIFT + USER_DYNPWD_SDED_ED_MONTH_BITS)
#define USER_DYNPWD_SDED_TAG_SHIFT	\
	(USER_DYNPWD_SDED_ED_YEAR_OFFSET_SHIFT + USER_DYNPWD_SDED_ED_YEAR_OFFSET_BITS)

#define USER_DYNPWD_SDED_TOTAL_BITS	\
	(USER_DYNPWD_SDED_TAG_SHIFT + USER_DYNPWD_SDED_TAG_BITS)
#define USER_DYNPWD_SDED_TOTAL_UNITS	\
	((USER_DYNPWD_SDED_TOTAL_BITS + 3) >> 2)

#define USER_DYNPWD_SDED_FIELD(value, FIELD)	\
	(((value) >> USER_DYNPWD_SDED_##FIELD##_SHIFT) \
		& USER_DYNPWD_SDED_FIELD_MASK(FIELD))

typedef struct _user_dynpwd_sded_data {
	gkt_date_u	start_date;
	gkt_date_u	expire_date;
} user_dynpwd_sded_data_s;

typedef struct _user_dynpwd_sded_item_data {
	uint32_t	start_date;
	uint32_t	expire_date;
} user_dynpwd_sded_item_data_s;

#if USER_DYNPWD_SDED_ENABLE
int user_dynpwd_SDED_retrieve(user_dynpwd_data_s *data,
				uint32_t *values);
int user_dynpwd_SDED_verify(user_dynpwd_data_s *data,
				uint32_t admin_item_index);
#else
#define user_dynpwd_SDED_retrieve	NULL
#define user_dynpwd_SDED_verify	NULL
#endif

#endif

